package com.hnnu.shoppingtoghter.demo.controller;

import com.hnnu.shoppingtoghter.demo.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hnnu.shoppingtoghter.demo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;
import java.sql.Date;

/*** @Description: 注册
 * @Author: PDY
 * @CreateTime： 2022/7/4 17:26 
 */
@Controller
@Slf4j
public class RegisterController {

    @Autowired
    private SysUserService userService;

    /**
     * pdy
     * 接收用户注册请求，响应注册页面
     *
     * @return
     */
    @GetMapping("/register")
    public String register() {
        return "/register";
    }

    /**
     * pdy
     * 将用户注册信息插入数据库
     */
    @PostMapping("/register")
    public String toRegister(SysUser user, HttpSession session,
                             String userCode, String password) {
        System.out.println("接收到用户新增的用户信息：" + user);

        /** 获取当前用户信息  将注册信息赋给新用户对象 */



        /** 调用  业务层 将用户信息 保存至数据库 */
        int rows = userService.insertUser(user);
        if (rows == 0) {
            System.out.println("用户信息插入注册失败");
        }
        return "redirect:/login";
    }

}
